let toastTimer: any = null;
export const showToast = (message: string, t?: number) => {

    let alert = document.getElementById("toast");

    if (alert == null) {
        alert = document.createElement("div");
        alert.id = "toast";
        alert.className = "fd";
        alert.innerText = message;
    } else {
        alert.style.opacity = 0.9;
    }
    document.body.appendChild(alert);
    t = t ? t : 1000;
    toastTimer = setTimeout(function () {
        hideToast();
    }, t);
}
const hideToast = () => {
    let alert = document.getElementById("toast");
    if (alert != null) {
        document.body.removeChild(alert);
        clearTimeout(toastTimer);
    }
}

export const hasClass = () => {
    let div = document.createElement("div");
    if ("classList" in div && typeof div.classList.contains === "function") {
        return function (elem, className) {
            return elem.classList.contains(className);
        };
    } else {
        return function (elem, className) {
            var classes = elem.className.split(/\s+/);
            for (var i = 0; i < classes.length; i++) {
                if (classes[i] === className) {
                    return true;
                }
            }
            return false;
        };
    }
}
